import { defineStore } from 'pinia'

export const useStore = defineStore('gwcc', {
  // 推荐使用 完整类型推断的箭头函数
  state: () => {
    return {
      gwc:[]
    }
  },actions:{
    GOU(item){
        let a = this.gwc.find((chlid =>chlid.goods_id == item.goods_id))
        if(!a){
            this.gwc.push(item)
        }
        else{
          a.count+=1
        }
    },jian(item){
      item.count-=1
    },
    sc(item,index){
      this.gwc.splice(index,1)
    }
  },
  getters:{
    gs(){
      return this.gwc.reduce((next,prev)=>{
        return prev+next.count
      },0)
    },  
    zj(){
      return this.gwc.reduce((next,prve)=>{
        return prve + next.count*next.goods_price*100
      },0)
    }
  }
})